﻿using System;
using System.Diagnostics;
using Bookvar.ApplicationModel;
using Bookvar.Collaboration;
using Bookvar.ObjectModel;

namespace BookvarWpf.Windows.Collaboration
{
    public partial class StartServerWindow : BookvarToolWindow
    {
        private readonly ICollaborationManager collaborationManager;
        private readonly MindMap currentMindMap;

        public StartServerWindow(MindMap currentMindmap)
        {
            if (currentMindmap == null)
            {
                throw new ArgumentNullException("currentMindmap");
            }

            InitializeComponent();

            this.currentMindMap = currentMindmap;
            collaborationManager = BookvarApplication.Current.ServiceLayer.GetService<ICollaborationManager>();
            Debug.Assert(collaborationManager != null);
        }

        private void StartServerBtn_Click(object sender, EventArgs e)
        {
            try
            {
                collaborationManager.StartServer(NameTextBox.Text, currentMindMap);
            }
            catch (Exception ex)
            {
                Logger.Log(ex.Message);
                throw;
            }
        }
    }
}